package top.skihub.mapper;

import org.apache.ibatis.annotations.*;
import top.skihub.pojo.ShoppingTrolley;
import java.util.List;

@Mapper
public interface ShoppingTrolleyMapper {
    @Insert("INSERT INTO shopping_trolley (user_id, goods_id, goods_img, goods_name, " +
            "goods_type, goods_desc, business_info, price, goods_enter_time2) " +
            "VALUES (#{userId}, #{goodsId}, #{goodsImg}, #{goodsName}, " +
            "#{goodsType}, #{goodsDesc}, #{businessInfo}, #{price}, #{goodsEnterTime2})")
    int insert(ShoppingTrolley trolley);

    @Select("SELECT * FROM shopping_trolley WHERE goods_id = #{goodsId} AND user_id = #{userId}")
    ShoppingTrolley selectByGoodsIdAndUserId(@Param("goodsId") Integer goodsId,
                                            @Param("userId") Integer userId);

    @Select("SELECT * FROM shopping_trolley WHERE user_id = #{userId} ORDER BY goods_enter_time2 DESC")
    List<ShoppingTrolley> getShoppingTrolley(@Param("userId") Integer userId);

    @Delete("DELETE FROM shopping_trolley WHERE goods_id = #{goodsId} AND user_id = #{userId}")
    void deleteShoppingTrolley(@Param("goodsId") Integer goodsId, @Param("userId") Integer userId);
}
